package com.atguigu.szdz.dcsyl.service.impl;

import com.atguigu.szdz.dcsyl.service.PmjlService;
import com.atguigu.szdz.dcsyl.utils.MapperUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("pmjlService")
public class PmjlServiceImpl implements PmjlService {
    @Autowired
    MapperUtils mapperUtils;

    @Override
    public void updateDate(String table_code, List<Map<String, String>> mapList) {
        mapperUtils.updataBySql("delete from dc_pmjl");
        String sql = "";
        for (Map<String, String> map : mapList) {
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaa:" + table_code + ",bbbbbbbbbbbbb:" + map);
            String Po = map.get("Po");
            String Ph = map.get("Ph");
            String Vo = map.get("Vo");
            String Vn = map.get("Vn");
            String n = map.get("n");
            String SH = map.get("SH");
            String Sh = map.get("Sh");
            String So = map.get("So");
            String tg = map.get("tg");
            String arf = map.get("arf");
            String UTI = map.get("UTI");
            String well_name = map.get("well_name");
            String depth = map.get("depth");
            sql = sql + "('" + Po + "','" + Ph + "','" + Vo + "','" + Vn + "','" + n + "','" + SH + "','" + Sh + "','" + So + "','" + tg
                    + "','" + arf + "','" + UTI + "','" + well_name + "','" + table_code + "','" + depth + "'),";
        }
        sql = "insert into dc_pmjl (po,ph,vo,vn,n,sh,sh2,so,tg,arf,uti,well_name,table_code,depth) values " + sql;
        sql = sql.replaceFirst(",$", "");
        System.out.println("sssssssssssssss:" + sql);
        mapperUtils.updataBySql(sql);
    }

    @Override
    public List<Map<String, Object>> getPmjlList(Integer currentPage, String keyword) {
        String sql = "select * from dc_pmjl" + keyword + " limit 10 offset " + (currentPage - 1) * 10;
        return mapperUtils.queryBySql(sql);
    }

    @Override
    public List<Map<String, Object>> getCount(String s) {
        return mapperUtils.queryBySql(s);
    }

    @Override
    public List<Map<String, Object>> getPmjlList() {
        return mapperUtils.queryBySql("select * from dc_pmjl");
    }
}
